<!--系统管理 --- 组织机构 --- 数据字典 -->
<template>
  <div class="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree">
      <div class="structureTree_title">
        <div>字典分类</div>
      </div>
      <!-- <el-tree :data="treeData" :props="defaultProps" :highlight-current="highlightBd" @node-click="handleNodeClick"
        node-key="fCompanyid" :accordion="true" :expand-on-click-node="false">
          </el-tree> -->
      <el-tree ref="tree" :default-checked-keys="expandedKeys" :default-expanded-keys="expandedKeys"
        :current-node-key="expandedKeys[0]" :data="treeData" :props="defaultProps" :highlight-current="highlightBd"
        @node-click="handleNodeClick" node-key="fItemcode" :accordion="true" :expand-on-click-node="false">
      </el-tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <div class="department_right_name">
        <div>字典数据 - {{ showName }}</div>
      </div>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left"></div>
        <!-- 顶部按钮 -->
        <div class="print">
          <div class="printTable">
            <!--  -->
            <el-button type="primary" icon="el-icon-refresh" size="small" @click="getDataList(fIstree, fItemcode)">
            </el-button>
            <el-button type="primary" icon="el-icon-circle-plus-outline" size="small" @click="editText(0)">新增
            </el-button>
            <el-button type="primary" icon="el-icon-edit" size="small" @click="editText(1)">编辑</el-button>
            <el-button type="primary" icon="el-icon-delete" size="small" @click="rowDelete(0)">删除</el-button>
            <el-button type="primary" icon="el-icon-folder-opened" size="small" @click="classification()">字典分类
            </el-button>
          </div>
        </div>
      </div>

      <!-- 表格 -->
      <div class="text_table">
        <el-table ref="multipleTable" v-loading="loading" element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.2)"
          @row-click="getRowInfo" :data="tableData" style="width: 100%" height="100%" stripe border highlight-current-row
          @current-change="rowChange">
          <el-table-column fixed type="index" width="50" align="center">
          </el-table-column>
          <el-table-column prop="fItemname" label="项目名" width="200" align="center">
            <!-- 超出鼠标滑过显示 -->
            <template slot-scope="scope">
              <div class="lineBoxhidden">
                <!-- <input type="text" v-model="scope.row.fItemname"> -->
                <a href="javascript:;" :title="scope.row.fItemname">{{
                  scope.row.fItemname
                }}</a>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="fItemvalue" label="项目值" width="200" align="center">
            <template slot-scope="scope">
              <div class="lineBoxhidden">
                <a href="javascript:;" :title="scope.row.fItemvalue">{{
                  scope.row.fItemvalue
                }}</a>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="fSortcode" label="排序" width="70" align="center" sortable>
            <template slot-scope="scope">
              <div class="lineBoxhidden">
                <a href="javascript:;" :title="scope.row.fSortcode">{{
                  scope.row.fSortcode
                }}</a>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="fEnabledmark" label="有效" width="100" align="center">
            <template slot-scope="scope">
              <el-switch v-model="value1" v-if="scope.row.fEnabledmark === 1" disabled>
              </el-switch>
              <el-switch v-model="value2" v-else-if="scope.row.fEnabledmark === 0" disabled>
              </el-switch>
            </template>
          </el-table-column>
          <el-table-column prop="fDescription" label="备注" width="250">
            <template slot-scope="scope">
              <div class="lineBoxhidden">
                <a href="javascript:;" :title="scope.row.fDescription">{{
                  scope.row.fDescription
                }}</a>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--弹框 编辑 -->
      <div class="Control-1 samll mechanism_dialog">
        <el-dialog :close-on-click-modal="false" :title="editDialog" v-dialogDrag :visible.sync="dialogTableVisible"
          v-loading="loadingDialog" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)">
          <div class="dialogBody common" :style="{ height: dialogHeight }">
            <el-form :model="formData" :rules="rules" ref="formData">
              <div class="tableRow">
                <el-form-item label="项目名" prop="fItemname" :label-width="formLabelWidth">
                  <el-input v-model="formData.fItemname" autocomplete="off" placeholder="请输入"></el-input>
                </el-form-item>
              </div>
              <div class="tableRow">
                <el-form-item label="项目值" prop="fItemvalue" :label-width="formLabelWidth">
                  <el-input v-model="formData.fItemvalue" autocomplete="off" placeholder="请输入"></el-input>
                </el-form-item>
              </div>
              <div class="tableRow">
                <el-form-item label="排序" prop="fSortcode" :label-width="formLabelWidth">
                  <el-input v-model="formData.fSortcode" autocomplete="off" placeholder="请输入"></el-input>
                </el-form-item>
              </div>

              <div class="tableRow">
                <el-form-item label="" prop="fEnabledmark" :label-width="formLabelWidth">
                  <el-checkbox v-model="formData.fEnabledmark" style="color: #000; font-size: 12px">有效</el-checkbox>
                </el-form-item>
              </div>

              <div class="tableRow" style="margin-top: 10px">
                <el-form-item label="备注" prop="fDescription" :label-width="formLabelWidth">
                  <el-input v-model="formData.fDescription" type="textarea" :rows="4" placeholder="请输入"
                    autocomplete="off">
                  </el-input>
                </el-form-item>
              </div>

              <el-form-item class="newlyAdded_btn">
                <el-button type="primary" @click="submitForm('formData')">保存1111</el-button>
                <el-button type="warning" @click="resetForm('formData')">关闭</el-button>
              </el-form-item>
            </el-form>
          </div>
        </el-dialog>
      </div>

      <!-- 字典分类 -->
      <div class="Control-1 mechanism_dialog dictionary">
        <el-dialog :close-on-click-modal="false" title="分类管理" v-dialogDrag :visible.sync="dialogTableVisibles"
          v-loading="loadingDialog" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)">
          <div class="dialogBody common" :style="{ height: dialogHeights }">
            <div class="dictionaryBox">
              <!-- 顶部导航栏 -->
              <div class="mechanism_nav">
                <!-- 左侧 -->
                <div class="mechanism_nav_left"></div>
                <!-- 顶部按钮 -->
                <div class="print">
                  <div class="printTable">
                    <!--  -->
                    <!-- <el-button
                      type="primary"
                      icon="el-icon-refresh"
                      size="small"
                      @click="getDataList(fIstree, fItemcode)"
                    ></el-button> -->

                    <el-button type="primary" icon="el-icon-circle-plus-outline" size="small" @click="CategoryBtn(0)">新增
                    </el-button>
                    <el-button type="primary" icon="el-icon-search" size="small" @click="CategoryBtn(1)">编辑</el-button>
                    <el-button type="primary" icon="el-icon-delete" size="small" @click="rowDelete(1)">删除</el-button>
                  </div>
                </div>
              </div>
              <!-- 表格 -->
              <div class="text_table mechanism_table commonTable" id="mianBody">
                <el-table ref="multipleTable" :data="treeData" style="width: 100%" height="100%" default-expand-all
                  :tree-props="{
                        children: 'children',
                        hasChildren: 'hasChildren',
                      }" @row-click="getRowInfoT" row-key="fItemid" v-loading="loading" element-loading-text="拼命加载中"
                  element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.2)" border stripe
                  highlight-current-row @current-change="rowChange">
                  <el-table-column fixed type="index" label="序号" width="50" align="center"></el-table-column>
                  <el-table-column prop="fItemname" label="名称" width="150" style="display: flex">
                    <template slot-scope="scope">
                      <a href="javascript:;" :title="scope.row.fItemname">{{
                        scope.row.fItemname
                      }}</a>
                    </template>
                  </el-table-column>
                  <el-table-column prop="fItemcode" label="编号" width="120">
                    <template slot-scope="scope">
                      <a href="javascript:;" :title="scope.row.fItemcode">{{
                        scope.row.fItemcode
                      }}</a>
                    </template>
                  </el-table-column>
                  <el-table-column prop="fSortcode" label="排序" width="70" align="center">
                  </el-table-column>
                  <el-table-column prop="fIstree" label="树型" width="70" align="center">
                    <template slot-scope="scope">
                      <el-switch v-model="value1" v-if="scope.row.fIstree === 1" disabled>
                      </el-switch>
                      <el-switch v-model="value2" v-else-if="scope.row.fIstree === 0" disabled>
                      </el-switch>
                    </template>
                  </el-table-column>
                  <el-table-column prop="fEnabledmark" label="有效" width="70" align="center">
                    <template slot-scope="scope">
                      <el-switch v-model="value1" v-if="scope.row.fEnabledmark === 1" disabled>
                      </el-switch>
                      <el-switch v-model="value2" v-else-if="scope.row.fEnabledmark === 0" disabled>
                      </el-switch>
                    </template>
                  </el-table-column>
                  <el-table-column prop="fDescription" label="备注">
                    <template slot-scope="scope">
                      <div style="
                          height: 23px !important;
                          overflow: hidden;
                          text-overflow: ellipsis;
                          white-space: nowrap;
                        ">
                        <a href="javascript:;" :title="scope.row.fDescription">{{ scope.row.fDescription }}</a>
                      </div>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </div>
        </el-dialog>
      </div>
      <!-- 字典分类弹框 -->
      <div class="Control-1 samll mechanism_dialog">
        <el-dialog :close-on-click-modal="false" :title="editDialog" v-dialogDrag :visible.sync="dialogTableVisibleText"
          v-loading="loadingDialog" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)">
          <div class="dialogBody common" :style="{ height: dialogHeightsT }">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
              <div class="tableRow">
                <el-form-item label="上级" prop="fParentNameT" :label-width="formLabelWidth">
                  <el-input v-model="fParentNameT" autocomplete="off" placeholder="系统自动填写" disabled></el-input>
                </el-form-item>
              </div>
              <div class="tableRow">
                <el-form-item label="名称" prop="fItemname" :label-width="formLabelWidth">
                  <el-input v-model="ruleForm.fItemname" autocomplete="off" placeholder="请输入"></el-input>
                </el-form-item>
              </div>
              <div class="tableRow">
                <el-form-item label="编号" prop="fItemcode" :label-width="formLabelWidth">
                  <el-input v-model="ruleForm.fItemcode" autocomplete="off" placeholder="请输入"></el-input>
                </el-form-item>
              </div>
              <div class="tableRow">
                <el-form-item label="排序" prop="fSortcode" :label-width="formLabelWidth">
                  <el-input v-model="ruleForm.fSortcode" autocomplete="off" placeholder="请输入"></el-input>
                </el-form-item>
              </div>
              <div class="tableRow">
                <el-form-item label="" prop="fIstree" :label-width="formLabelWidth">
                  <el-checkbox v-model="ruleForm.fIstree" style="color: #000; font-size: 12px">树形</el-checkbox>
                </el-form-item>

                <el-form-item label="" prop="fEnabledmark" :label-width="formLabelWidth">
                  <el-checkbox v-model="ruleForm.fEnabledmark" style="color: #000; font-size: 12px">有效</el-checkbox>
                </el-form-item>
              </div>

              <div class="tableRow" style="margin-top: 10px">
                <el-form-item label="备注" prop="fDescription" :label-width="formLabelWidth">
                  <el-input v-model="ruleForm.fDescription" type="textarea" :rows="4" placeholder="请输入"
                    autocomplete="off">
                  </el-input>
                </el-form-item>
              </div>

              <el-form-item class="newlyAdded_btn">
                <el-button type="primary" @click="submitFormT()">保存</el-button>
                <el-button type="warning" @click="resetForm('ruleForm')">关闭</el-button>
              </el-form-item>
            </el-form>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getBaseDataitemList,
  getBaseDataitemDetailByItemCode,
  addBaseDataitem,
  getBaseDataitemByFid,
  delBaseDataitem,
  addBaseDataitemDetail,
  getBaseDataitemDetailByFid,
  delBaseDataitemDetail,
} from "@/api/request.js";
export default {
  inject: ["reload"],
  name: "Home",
  data() {
    return {
      value1: true, //列表展示有效
      value2: false,
      currentPage4: 4,
      checked: false, //查看下级
      showName: "未选择字典分类",
      dialogHeight: "",
      dialogHeights: "",
      dialogHeightsT: "",
      expandedKeys: null,
      fId: null, //当前数据fId
      projectName: null, //项目名称
      loading: false,
      highlightBd: true, //左侧机构树停留背景色
      dialogFormVisible: false,
      // 弹框
      Effective: true, //有效
      editDialog: null,
      rules: {
        fItemname: [{ required: true, message: "请输入", trigger: "blur" }],
        fItemcode: [{ required: true, message: "请选择", trigger: "blur" }],
        fSortcode: [{ required: true, message: "请选择", trigger: "blur" }],
        fItemvalue: [{ required: true, message: "请选择", trigger: "blur" }],
      },
      // 新增/编辑
      loadingDialog: false,
      dialogTableVisible: false,
      formData: {
        fItemdetailid: "", //字典类型主键id
        fItemid: "", //字典主键id
        fItemname: "", //项目名
        fItemvalue: "", //项目值
        fEnabledmark: true, //是否启用 1是0否
        fDescription: "", //备注
        fSortcode: "", //排序号
      },
      row: null,
      row1: null,
      companyTree: "", //所有数据
      fParentName: "", //父级名称

      formLabelWidth: "70px",
      treeData: [], //左侧树
      treeCompanyid: "", //点击机构树带出id
      fItemcode: "", //点击机构树带出字典编码
      fIstree: "", //点击机构树带出能否新增 1是0否
      fItemid: "", //点击机构树带出字典主键id
      fItemdetailid: "",
      tableData: [], //表格数据列表
      // 左侧机构树
      defaultProps: {
        children: "children",
        label: "fItemname",
      },
      dialogVisible: false,
      //   字典分类
      dialogTableVisibles: false,
      // 字典分类弹框
      dialogTableVisibleText: false,
      dialog_fItemid: "",
      fParentNameT: "",
      ruleForm: {
        fItemid: "", //字典主键id
        fParentid: "", //字典父id
        fItemcode: "", //字典编码
        fItemname: "", //字典名称
        fIstree: false, //树状  1是0否
        fSortcode: "", //排序号
        fDescription: null, //备注
        fEnabledmark: true, //有效
      },
    };
  },
  mounted() {
    this.getHeight();
    // this.getData();
    // this.getData1();
    this.getTree();
  },
  // 卡卡1 fItemid
  destroyed() {
    sessionStorage.removeItem("treeId");
    sessionStorage.removeItem("expandedKeys");
  },
  // 卡卡1
  methods: {
    // 左侧树结构
    getTree() {
      getBaseDataitemList({})
        .then((res) => {
          if (res.errcode == 0) {
            this.companyTree = res.data.baseDataitemList;
            var that = this;
            setTimeout(() => {
              that.treeData = that.tranListToTreeData(that.companyTree);

              // 卡卡2
              var id;
              if (
                sessionStorage.getItem("treeId") != null &&
                sessionStorage.getItem("treeId") != ""
              ) {
                id = JSON.parse(sessionStorage.getItem("treeId"));
                that.fItemcode = id.fItemcode;
                that.fIstree = id.fIstree;
                that.showName = id.fItemname + "(" + id.fItemcode + ")";
              } else {
                id = that.treeData[0];
                that.fItemcode = id.fItemcode;
                that.fIstree = id.fIstree;
                that.showName =
                  that.treeData[0].fItemname +
                  "(" +
                  that.treeData[0].fItemcode +
                  ")";
              }

              if (
                sessionStorage.getItem("expandedKeys") != null &&
                sessionStorage.getItem("expandedKeys") != ""
              ) {
                console.log('ttttt', JSON.parse(
                  sessionStorage.getItem("expandedKeys")
                ));
                that.expandedKeys = JSON.parse(
                  sessionStorage.getItem("expandedKeys")
                );
                console.log('yyyyy', that.expandedKeys);
              }
              else {
                console.log('uuuuu');
                that.expandedKeys = []; //默认展开

                // that.expandedKeys = [that.treeData[0].fItemcode]; //默认展开
              }

              that.getDataList(that.treeData[0].fIstree, id.fItemcode);

              // this.$nextTick(() => {
              //   // 先给tree 加ref
              //   this.$refs.tree.setCurrentKey(sessionStorage.getItem("treeId"));
              // });
              // 卡卡2

              that.$nextTick(() => {
                that.$refs.multipleTable.doLayout();
              });
            }, 200);
          } else {
            this.$message.error(res.msg);
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },
    tranListToTreeData(data) {
      let result = [];
      if (!Array.isArray(data)) {
        return result;
      }
      // 清除已存在的children 重新赋值
      data.forEach((item) => {
        delete item.children;
      });

      let map = {};
      data.forEach((item) => {
        map[item.fItemid] = item;
      });

      data.forEach((item) => {
        let parent = map[item.fParentid];
        if (parent) {
          (parent.children || (parent.children = [])).push(item);
        } else {
          result.push(item);
        }
      });
      return result;
    },
    // 点击左侧机构树
    handleNodeClick(data) {

      this.fItemdetailid = "";
      this.dialog_fItemid = "";
      this.showName = data.fItemname + "(" + data.fItemcode + ")"; //顶部显示机构名
      this.fItemid = data.fItemid;
      this.fItemcode = data.fItemcode;

      this.fIstree = data.fIstree;
      this.getDataList(this.fIstree, this.fItemcode);

      // data.fItemcode
      // 卡卡3
      this.expandedKeys = [data.fItemcode];
      console.log(8888, data.fItemcode, this.expandedKeys);
      window.sessionStorage.setItem(
        "expandedKeys",
        JSON.stringify(this.expandedKeys)
      );

      window.sessionStorage.setItem("treeId", JSON.stringify(data));
    },
    // 获取列表数据
    getDataList(num, code) {
      console.log("页面刷新", num, code);
      this.loading = true;
      if (num == 0) {
        getBaseDataitemDetailByItemCode({ fItemcode: code })
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              that.loading = false;
              that.tableData = res.data.baseDataitemdetailList;
              setTimeout(() => {
                that.$nextTick(() => {
                  that.$refs.multipleTable.doLayout();
                });
              }, 200);
            } else {
              this.$message.error("列表数据1", res.msg);
              this.loading = false;
            }
          })
          .catch(() => {
            console.log("列表数据接口报错");
            this.loading = false;
          });
      } else {
        getBaseDataitemDetailByItemCode({})
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              that.tableData = res.data.baseDataitemdetailList;
              that.loading = false;
            } else {
              this.$message.error("列表数据2", res.msg);
              this.loading = false;
            }
          })
          .catch(() => {
            console.log("列表数据接口报错");
            this.loading = false;
          });
      }
    },
    // 新增/编辑
    editText(num) {
      if (num == 0) {
        // 新增
        if (this.fIstree == 0) {
          this.dialogTableVisible = true;
          this.editDialog = "添加字典";
          this.formData = {
            fItemdetailid: "", //字典类型主键id
            fItemid: "", //字典主键id
            fItemname: "", //项目名
            fItemvalue: "", //项目值
            fEnabledmark: true, //是否启用 1是0否
            fDescription: "", //备注
            fSortcode: "", //排序号
          };
          this.formData.fItemid = this.fItemid;
        } else {
          this.$message.error("请选择可以添加项目的字典项");
          return false;
        }
      } else {
        // 编辑
        if (this.fItemdetailid != "" && this.fItemdetailid != null) {
          this.dialogTableVisible = true;
          this.loadingDialog = true;
          this.editDialog = "编辑字典";
          getBaseDataitemDetailByFid({
            fItemdetailid: this.fItemdetailid,
          })
            .then((res) => {
              if (res.errcode == 0) {
                var that = this;
                that.loadingDialog = false;
                that.formData = res.data.lrBaseDataitemdetail;
                //  有效
                if (that.formData.fEnabledmark == 1) {
                  that.formData.fEnabledmark = true;
                } else {
                  that.formData.fEnabledmark = false;
                }
              } else {
                this.$message.error("编辑", res.msg);
                this.loadingDialog = false;
              }
            })
            .catch(() => {
              console.log("编辑详情接口报错");
              this.loadingDialog = false;
            });
        } else {
          this.$message.error("请先选择要编辑的数据");
          return false;
        }
      }
    },
    // 保存
    submitForm() {
      this.$refs.formData.validate((valid) => {
        if (valid) {
          if (this.formData.fEnabledmark == true) {
            this.formData.fEnabledmark = 1;
          } else if (this.formData.fEnabledmark == false) {
            this.formData.fEnabledmark = 0;
          }
          this.loadingDialog = true;
          var that = this;
          addBaseDataitemDetail(that.formData)
            .then((res) => {
              if (res.errcode == 0) {
                // this.reload();
                // 卡卡5
                this.getDataList(this.fIstree, this.fItemcode);
                this.dialogTableVisible = false;
                // this.getTree();
                // 卡卡5
                this.$message.success("新增成功");
                this.loadingDialog = false;
              } else {
                this.$message.error("新增失败", res.msg);
                this.loadingDialog = false;
                return false;
              }
            })
            .catch(() => {
              console.log("新增失败");
              this.loadingDialog = false;
            });
        } else {
          this.$message.error("请填写必填项");
          return false;
        }
      });
    },
    // 分类------ 新增/编辑
    CategoryBtn(num) {
      if (num == 0) {
        // 分类新增
        this.dialogTableVisibleText = true;
        this.editDialog = "添加分类";
        this.fParentNameT = this.row1.fItemname;
        this.ruleForm = {
          fItemid: "", //字典主键id
          fParentid: "", //字典父id
          fItemcode: "", //字典编码
          fItemname: "", //字典名称
          fIstree: false, //树状  1是0否
          fSortcode: "", //排序号
          fDescription: null, //备注
          fEnabledmark: true, //有效
        };
        if (this.dialog_fItemid != "" && this.dialog_fItemid != null) {
          this.ruleForm.fParentid = this.dialog_fItemid;
        } else {
          this.ruleForm.fParentid = "0";
        }
      } else {
        // 分类编辑
        if (this.dialog_fItemid != "" && this.dialog_fItemid != null) {
          this.dialogTableVisibleText = true;
          this.loadingDialog = true;
          this.editDialog = "编辑";
          this.fParentNameT = "";
          //通过父id  找全称

          for (let i = 0; i < this.companyTree.length; i++) {
            if (this.row1.fParentid == this.companyTree[i].fItemid) {
              this.fParentNameT = this.companyTree[i].fItemname;
            }
          }

          getBaseDataitemByFid({ fItemid: this.dialog_fItemid })
            .then((res) => {
              if (res.errcode == 0) {
                var that = this;
                that.ruleForm = res.data.lrBaseDataitem;
                //  有效
                if (res.data.lrBaseDataitem.fEnabledmark == 1) {
                  that.ruleForm.fEnabledmark = true;
                } else {
                  that.ruleForm.fEnabledmark = false;
                }
                //  是否可新增
                if (res.data.lrBaseDataitem.fIstree == 1) {
                  that.ruleForm.fIstree = true;
                } else {
                  that.ruleForm.fIstree = false;
                }
                that.loadingDialog = false;
              } else {
                this.$message.error("分类编辑", res.msg);
                this.loadingDialog = false;
              }
            })
            .catch(() => {
              console.log("分类编辑");
              this.loadingDialog = false;
            });
        } else {
          this.$message.error("请先选择要编辑的数据");
          return false;
        }
      }
    },

    //分类----- 保存：
    submitFormT() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          if (this.ruleForm.fIstree == true) {
            this.ruleForm.fIstree = 1;
          } else if (this.ruleForm.fIstree == false) {
            this.ruleForm.fIstree = 0;
          }
          if (this.ruleForm.fEnabledmark == true) {
            this.ruleForm.fEnabledmark = 1;
          } else if (this.ruleForm.fEnabledmark == false) {
            this.ruleForm.fEnabledmark = 0;
          }
          var that = this;
          addBaseDataitem(that.ruleForm)
            .then((res) => {
              if (res.errcode == 0) {
                // this.reload();
                this.getDataList(this.fIstree, this.fItemcode);
                this.dialogTableVisibleText = false;
                this.getTree();
                this.$message.success("新增成功");
              } else {
                this.$message.error("分类---保存失败", res.msg);
                // this.$message.error("");
                return false;
              }
            })
            .catch(() => {
              console.log("分类---保存失败");
            });
        } else {
          this.$message.error("请填写必填项");
          return false;
        }
      });
    },
    // 关闭
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.dialogTableVisibleText = false;
      this.dialogTableVisible = false;
    },
    // 列表-----点击当前行
    getRowInfo(e) {
      this.row = e;
      this.fItemdetailid = e.fItemdetailid;
    },
    // 分类-----点击当前行
    getRowInfoT(e) {
      this.row1 = e;
      this.dialog_fItemid = e.fItemid;
    },
    // 点击当前行变色
    rowChange(val) {
      this.currentRow = val;
    },

    // 获取页面容器高度
    getHeight() {
      var h = document.documentElement.clientHeight; //获取页面可见高度
      this.dialogHeight = h * 0.3 + "px";
      this.dialogHeights = h * 0.7 + "px";
      this.dialogHeightsT = h * 0.4 + "px";
    },

    // 删除
    rowDelete(num) {
      if (num == 0) {
        if (this.fItemdetailid != "") {
          this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.loading = true;

              delBaseDataitemDetail({ fItemdetailid: this.fItemdetailid })
                .then((res) => {
                  if (res.errcode == 0) {
                    // 卡卡4
                    this.getDataList(this.fIstree, this.fItemcode);
                    // this.getTree();
                    // 卡卡4
                    this.$message.success("删除成功");
                    this.loading = false;
                  } else {
                    this.$message.error("删除失败", res.msg);
                    this.loading = false;

                    return false;
                  }
                })
                .catch(() => {
                  console.log("删除失败");
                  this.loading = false;
                });
            })
            .catch(() => {
              this.$message("取消删除");
            });
        } else {
          this.$message.error("请选择要删除的数据");
          return false;
        }
      } else if (num == 1) {
        // 分类-----删除
        if (this.dialog_fItemid != "") {
          if (this.row1.children == undefined) {
            this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            })
              .then(() => {
                this.loading = true;
                delBaseDataitem({ fItemid: this.dialog_fItemid })
                  .then((res) => {
                    if (res.errcode == 0) {
                      this.loading = false;

                      this.getDataList(this.fIstree, this.fItemcode);
                      // this.dialogTableVisibleText = false;
                      // this.getTree();
                      this.dialog_fItemid = "";
                      this.$message.success("删除成功");
                    } else {
                      this.$message.error("分类---删除失败", res.msg);
                      this.loading = false;
                      return false;
                    }
                  })
                  .catch(() => {
                    console.log("分类---删除失败");
                    this.loading = false;
                  });
              })
              .catch(() => {
                this.$message("取消删除");
              });
          } else {
            this.$message.error("存在下级,不可删除");
            return false;
          }
        } else {
          this.$message.error("请选择要删除的分类数据");
          return false;
        }
      }
    },

    // 字典分类
    classification() {
      this.dialogTableVisibles = true;
    },
  },
};
</script>

<style scoped  lang="less">
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

/* 字典分类弹框 */
.dictionary {
  .dialogBody {
    overflow: hidden;
    padding: 5px !important;
    box-sizing: border-box;
    position: relative;

    .dictionaryBox {
      width: 100%;
      height: 100%;
      box-sizing: border-box;
      border: 1px solid #ccc;
      display: flex;
      flex-direction: column;

      .mechanism_nav {
        border: none;
        border-radius: 0%;
        margin-top: 3px;
        padding: 0;
        height: 35px;

        .printTable {
          margin-right: 10px;

          .el-button--small {
            padding: 5px 5px !important;
          }

          .el-button {
            height: 25px;
          }

          .el-button+.el-button {
            margin-left: 5px;
          }
        }
      }

      .text_table {
        flex: 1;
        overflow: auto;

        .el-table .cell {
          height: 30px !important;
          line-height: 30px !important;
        }
      }
    }
  }
}

a {
  text-decoration: none;
  color: #000;
}
</style>